<template>
  <Modal
    v-model="form.visible"
    :width="1000"
    :mask-closable="false"
    :loading="loading"
    title="上传图片"
    ok-text="提交"
    @on-ok="ok">
    <Row class="mt20">
      <Col span="16" offset="4">
        <Form ref="form" :model="form.data" :label-width="120">
          <FormItem label="活动照片">
            <upload-img ref="uploadImg" v-if="form.visible"></upload-img>
          </FormItem>
        </Form>
      </Col>
    </Row>
  </Modal>
</template>

<script>
  import uploadImg from '@/components/upload-img'
  import activityApi from '@/api/activity'

  export default {
    name: 'update-modal',
    props: [
      'form'
    ],
    components: {
      uploadImg
    },
    data () {
      return {
        loading: true
      }
    },
    methods: {
      ok () {
        this.submitForm()
      },
      async submitForm () {
        let { uploadList } = this.$refs.uploadImg
        this.form.data.photoPathLs = uploadList.map((item) => {
          return item.response.responseData
        })
        const { body } = await activityApi.photo.create(this.form.data)
        if (this.$apiHelper.requestSuccessed(body.responseCode)) {
          this.form.visible = false
          this.$refs.form.resetFields()
          this.$emit('submit')
        } else {
          setTimeout(() => {
            this.$Modal.error({
              title: '错误',
              content: body.desc,
              onOk: () => {}
            })
          }, 500)
        }
      }
    }
  }
</script>
